package com.guigu.base.service.impl;

import com.guigu.base.entity.Truck;
import com.guigu.base.entity.TruckLicense;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.base.mapper.TruckLicenseMapper;
import com.guigu.base.service.TruckLicenseService;
import com.guigu.base.service.TruckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 车辆行驶证表 服务实现类
 * </p>
 *
 * @author TaoLong
 * @since 2021-11-08
 */
@Service
public class TruckLicenseServiceImpl extends ServiceImpl<TruckLicenseMapper, TruckLicense> implements TruckLicenseService {
    @Autowired
    private TruckService truckService;
    /**
     * 保存车辆行驶证信息
     *
     * @param pdTruckLicense 车辆行驶证信息
     * @return 车辆行驶证信息
     */
    @Override
    public TruckLicense saveTruckLicense(TruckLicense pdTruckLicense) {
        if (pdTruckLicense.getId() == null) {
            baseMapper.insert(pdTruckLicense);
            // 处理车辆信息中的关联字段
            if (pdTruckLicense.getTruckId() != null) {
                Truck pdTruck = truckService.getById(pdTruckLicense.getTruckId());
                pdTruck.setTruckLicenseId(pdTruckLicense.getId());
                truckService.updateById(pdTruck);
            }
        } else {
            baseMapper.updateById(pdTruckLicense);
        }
        return pdTruckLicense;
    }
}
